class Integer
    def !
        raise StandardError, "Number must be nonnegative." if self < 0 
        f = 1
        (1..self).each do |v|
            f *= v
        end
        return f
    end
end


def f(n)
    raise StandardError, "n must be integer and positive." if n < 1 or not n.kind_of?(Integer)
    s = 0
    all = 0
    (1..2*n-1).each do |i|
        (i+1..2*n).each do |j|
            if i + j != 2*n + 1
                s += 1
            end
            all += 1
        end
    end
    puts "n = #{n}: s = #{s}, all = #{all} (#{(2*n).!/(2*(2*n-2).!)}), all-n = #{all-n}, 3*n=#{3*n}"
    return s
end

(1..20).each do |n|
    puts "n = #{n}: s1 = #{f(n)}, s2 = #{3**n}"
end